package com.linln.modules.message.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.linln.modules.message.domain.MessageDayCount;


/**
 * @author hct
 * @date 2019/09/12
 */
public interface MessageDayCountRepository extends JpaRepository<MessageDayCount, Long> {
	
	/**
	 * 定时执行数据  
	 * @return
	 */
    @Transactional
    @Modifying
	@Query(value="INSERT INTO message_daycount(area,num,create_date,update_date) SELECT area,count(area), DATE_SUB(CURDATE(), INTERVAL 1 DAY),now() FROM messageinfo where to_days(create_date) = to_days(DATE_SUB(curdate(),INTERVAL 1 DAY)) and message_status=1  group by area ",nativeQuery = true)
	public Integer insert();

	/**
	 * 定时执行数据
	 * @return
	 */
	@Transactional
	@Query(value="SELECT count(*) FROM message_daycount where to_days(create_date) = to_days(DATE_SUB(curdate(),INTERVAL 1 DAY)) ",nativeQuery = true)
	public Integer dayCount();

}